﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SmartCity.Shared;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;

namespace CommonManagement
{
    /// <summary>
    /// 积分控制器
    /// </summary>
    [Authorize]
    [RemoteService]
    [Area("commonManagement")]
    [Route("api/commonManagement/scores")]
    public class ScoreController : AbpController, IScoreAppService
    {
        private readonly IScoreAppService _scoreAppService;

        public ScoreController(
            IScoreAppService scoreAppService)
        {
            _scoreAppService = scoreAppService;
        }

        // 列表
        [HttpGet]
        [Route("list")]
        public Task<ListResponse<ScoreDto>> PagedListAsync(PagedListRequest request)
        {
            return _scoreAppService.PagedListAsync(request);
        }

        // 积分排行榜
        [HttpGet]
        [Route("top/list")]
        public Task<ListResponse<TopDto>> TopListAsync()
        {
            return _scoreAppService.TopListAsync();
        }

        // 积分兑换
        [HttpPost]
        [Route("consume/{productId:int}")]
        public Task<ActionResponse> ConsumeAsync(int productId)
        {
            return _scoreAppService.ConsumeAsync(productId);
        }
    }
}